package com.atfusu.service.impl;

import com.atfusu.base.BaseDao;
import com.atfusu.base.impl.BaseServiceImpl;
import com.atfusu.bean.entity.House;
import com.atfusu.bean.vo.HouseQueryVo;
import com.atfusu.bean.vo.HouseVo;
import com.atfusu.dao.DictDao;
import com.atfusu.dao.HouseDao;
import com.atfusu.service.HouseService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Title:
 * Author: fusu
 * DateTime:  2022/11/29
 * Description:
 **/
@DubboService
public class HouseServiceImpl extends BaseServiceImpl<House> implements HouseService {

    @Autowired
    private HouseDao houseDao;

    @Autowired
    private DictDao dictDao;

    @Override
    protected BaseDao<House> getEntityDao() {
        return houseDao;
    }

    //修改发布状态
    @Override
    public void publish(Long id, Integer status) {
        houseDao.publish(id, status);
    }


    /**
     * 用于获取house查看详情时可以显示信息的house对象
     */
    @Override
    public House showById(Long id) {
        House house = houseDao.getById(id);
        //户型名称
        String houseTypeName = dictDao.getNameById(house.getHouseTypeId());
        //楼层名称
        String floorName = dictDao.getNameById(house.getFloorId());
        //建筑结构
        String BuildStructureName = dictDao.getNameById(house.getBuildStructureId());
        //朝向
        String DirectionName = dictDao.getNameById(house.getDirectionId());
        //装修情况
        String DecorationName = dictDao.getNameById(house.getDecorationId());
        //房屋用途
        String HouseUseName = dictDao.getNameById(house.getHouseUseId());
        //将这些名字set到house对象内用于前端show页面的显示
        house.setHouseTypeName(houseTypeName);
        house.setFloorName(floorName);
        house.setBuildStructureName(BuildStructureName);
        house.setDirectionName(DirectionName);
        house.setDecorationName(DecorationName);
        house.setHouseUseName(HouseUseName);
        return house;
    }

    @Override
    public PageInfo<HouseVo> findListPage(Integer pageNum, Integer pageSize, HouseQueryVo houseQueryVo) {
        PageHelper.startPage(pageNum, pageSize);
        //将查询条件传入dao层进行查询
        List<HouseVo> houseVoList = houseDao.findListPage(houseQueryVo);
        for (HouseVo houseVo : houseVoList) {
            //遍历为name属性赋值
            houseVo.setHouseTypeName(dictDao.getNameById(houseVo.getHouseTypeId()));
            houseVo.setFloorName(dictDao.getNameById(houseVo.getFloorId()));
            houseVo.setDirectionName(dictDao.getNameById(houseVo.getDirectionId()));
        }
        return new PageInfo<HouseVo>(houseVoList, 5);
    }


}
